package com.xiaozheng.reflex;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @Package: com.xiaozheng.reflex
 * @ClassName: ReflectionCase
 * @Author: 小政同学    QQ:xiaozheng666888@qq.com
 * @CreateTime: 2020/10/16 10:37
 */
public class ReflectionCase {
    public static void main(String[] args) throws Exception{
        //1.加载配置文件
        Properties pro = new Properties();
        //2.加载配置文件，进内存
        try {
            pro.load( ReflectionCase.class.getClassLoader().getResourceAsStream("pro.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        //3.获取配置文件中定义的数据
        String className = pro.getProperty("className");
        String methodName = pro.getProperty("methodName");

        //4.加载配置文件中定义的类进内存
        Class aClass = Class.forName(className);
        //5.创建对象
        Object o = aClass.newInstance();

        //6.获取对象中的方法
        Method method = aClass.getMethod(methodName, String.class);
        method.setAccessible(true);
        method.invoke(o, "李四");
        System.out.println("o.toString() = " + o.toString());
    }
}
